#FROM alpine:latest
#
#ADD admission-webhook-demo /admission-webhook-demo
#ENTRYPOINT ["./admission-webhook-demo"]

# syntax=docker/dockerfile:1
# Build the webhook binary
FROM golang:1.18 as builder

# RUN apt-get -y update && apt-get -y install upx

WORKDIR /workspace
# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum

# Copy the go source
COPY main.go main.go
COPY service service

# Build
ENV CGO_ENABLED=0
ENV GOOS=linux
ENV GOARCH=amd64
ENV GO111MODULE=on
ENV GOPROXY="https://goproxy.cn"

# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN --mount=type=cache,mode=0777,id=go-mod,target=/go/pkg/mod  go mod download && \
    go build -a -o admission-webhook-demo main.go
#    upx admission-webhook-demo

FROM alpine:3.9.2
COPY --from=builder /workspace/admission-webhook-demo .
ENTRYPOINT ["/admission-webhook-demo"]